home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / Reinstallable / Reinstallable README < prev    next >
Encoding:
Text File  |  1993-10-07  |  2.5 KB  |  60 lines  |  [TEXT/ttxt]

  1. /*
  2.  *  Sample reinstallable init
  3.  *  v 1.0
  4.  *
  5.  *  August 1993  Greg Robbins
  6.  *
  7.  *  This sample INIT patches a trap globally yet is reinstallable:
  8.  *  it can be recompiled and run without rebooting.
  9.  *
  10.  *  Usually, when an INIT patches a trap, changing the INIT requires
  11.  *  reinstalling the INIT in the Extensions folder and rebooting.
  12.  *  This INIT demonstrates a technique which allows new INIT code to
  13.  *  replace most of the old code without the developer having to reboot.
  14.  *
  15.  *  This INIT just patches Standard File (_Pack3) and beeps when
  16.  *  a standard file dialog is raised.
  17.  *
  18.  *  Demonstration:
  19.  *
  20.  *  • put the Reinstallable Init in the Extensions folder and reboot
  21.  *  • bring up a standard file dialog; notice the beep
  22.  *  • drag the Reinstallable twoBeep INIT file onto the
  23.  *    LaunchInits program
  24.  *  • bring up a standard file dialog again and notice both beeps 
  25.  *
  26.  *  The trick is to keep a global handle in the system heap containing 
  27.  *  the addresses of the routines we want executed for each
  28.  *  patched item.  The handle to the globals is available via Gestalt.
  29.  *
  30.  *  A permanently installed dispatcher routine (part of the init code)
  31.  *  is used to get the address of our patch routine and jump to it.
  32.  *
  33.  *  The second time the init code runs, it will use the existing global
  34.  *  handle, and just update the addresses of our patch routines so the
  35.  *  dispatcher code jumps to the correct places.
  36.  *
  37.  *  A couple of critical items:
  38.  *    - The init loaded at boot time contains the patch dispatchers, so
  39.  *      it must never be disposed of.  We will simply strand it in the
  40.  *      heap when the first reinstallation occurs.
  41.  *    - If we change anything about which routines are patched, this invalidates
  42.  *      the global handle struct format, so we must reboot
  43.  *    - Similarly, if the dispatching code is changed, we must reboot
  44.  *      since only the dispatching code from the first time the init is
  45.  *      installed can be used.
  46.  *    - The dispatch and patch routines destroy registers, so they
  47.  *      may not be suitable for OS patches
  48.  *
  49.  *  Globals:
  50.  *
  51.  *  Since this code only uses a single true global (a handle to our
  52.  *  globals in the system heap) I used a simpler method than Think C's
  53.  *  A4 globals.  The global handle is stored smack in the middle of the
  54.  *  GetGlobalsHandleFromStorage routine. Calling GGHFS with a handle
  55.  *  stores the handle there; calling GGHFS with no parameter returns
  56.  *  the stored handle.  (The handle can also be retrieved from
  57.  *  Gestalt, but that is too slow a method for use in a trap patch.)
  58.  *  
  59.  */
  60.